package com.lz.ovuola.service.assembler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lz.ovuola.entity.PhysiologicalBasisDo;
import com.lz.ovuola.service.dto.PhysiologicalBasisDto;
import com.lz.ovuola.util.exception.BusinessException;
import com.lz.ovuola.util.exception.msg.CommonMsgEnum;
import com.lz.ovuola.util.threadlocal.UserContextHolder;

/**
 * 包装工具
 * 
 * @author fz
 *
 */
public class PhysiologicalBasisAssembler implements
		Assembler<PhysiologicalBasisDto> {

	private Logger logger = LoggerFactory
			.getLogger("PhysiologicalBasisAssembler");
	private static final PhysiologicalBasisAssembler ASSEMBLER = new PhysiologicalBasisAssembler();

	private PhysiologicalBasisAssembler() {
		super();
	}

	@Override
	public PhysiologicalBasisDto toDto(Object object) throws Exception {

		if (object instanceof PhysiologicalBasisDo) {
			PhysiologicalBasisDo physiologicalBasisDo = (PhysiologicalBasisDo) object;
			PhysiologicalBasisDto dto = new PhysiologicalBasisDto();
			dto.setCycleFloatingDays(physiologicalBasisDo
					.getCycleFloatingDays());
			dto.setMenstruationLength(physiologicalBasisDo
					.getMenstruationLength());
			dto.setPhysiologicalLength(physiologicalBasisDo
					.getPhysiologicalLength());
			dto.setStartTime(physiologicalBasisDo.getStartTime());
			return dto;
		} else {
			logger.error(
					"---用户id：{},PhysiologicalBasisDo转PhysiologicalBasisDto过程中出现异常",
					UserContextHolder.get().getUserId());// UserContextHolder
			throw new BusinessException(
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getStatus(),
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getMsg());
		}
	}

	public PhysiologicalBasisDto toDtoMenst(Object object) throws Exception {

		if (object instanceof PhysiologicalBasisDo) {
			PhysiologicalBasisDo physiologicalBasisDo = (PhysiologicalBasisDo) object;
			PhysiologicalBasisDto dto = new PhysiologicalBasisDto();
			dto.setMenstruationDate(physiologicalBasisDo
					.getMenstruationHistory());
			return dto;
		} else {
			logger.error(
					"---用户id：{},PhysiologicalBasisDo转PhysiologicalBasisDto过程中出现异常",
					UserContextHolder.get().getUserId());// UserContextHolder
			throw new BusinessException(
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getStatus(),
					CommonMsgEnum.SERVER_INTERNAL_ERROR.getMsg());
		}
	}

	public static PhysiologicalBasisAssembler getPhysiologicalBasisAssembler() {
		return ASSEMBLER;
	}

}
